package com.sunyard.manage.controller;

import com.sunyard.constant.ErrMessageConst;
import com.sunyard.dal.bo.*;
import com.sunyard.dal.bo.finger.*;
import com.sunyard.dal.dto.DownloadFingerResDTO;
import com.sunyard.dal.dto.FingerCopyQueryResDTO;
import com.sunyard.dal.dto.OpFingerResDTO;
import com.sunyard.manage.service.FingerService;
import com.sunyard.utils.Response.BaseResult;
import com.sunyard.utils.Response.GetResult;
import com.sunyard.utils.manage.DataGrid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "FingerController", description = "指纹管理")
@Slf4j
@RestController
@RequestMapping(value = "/finger", method = RequestMethod.POST)
public class FingerController {

    @Autowired
    private FingerService fingerService;

    @RequestMapping(value = "/addFigner", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("指纹录入")
    public BaseResult addFigner(@Validated @RequestBody FingerAddBO addBO, HttpServletRequest request) {
        try {
            return fingerService.addFigner(addBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }

    @RequestMapping(value = "/getOpFigner", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取指定用户的指纹列表")
    public BaseResult<List<OpFingerResDTO>> getOpFigner(@Validated @RequestBody OpFingerReqBO reqBO, HttpServletRequest request) {
        try {
            return fingerService.getOpFigner(reqBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }

    @RequestMapping(value = "/deleteOpFinger", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("删除指定人员指纹信息")
    public BaseResult deleteOpFinger(@Validated @RequestBody FingerDeleteBO deleteBO, HttpServletRequest request) {
        try {
            return fingerService.deleteOpFinger(deleteBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }

    @RequestMapping(value = "/getFingerCopyByPage", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("分页查询指纹审核信息")
    public BaseResult<DataGrid<FingerCopyQueryResDTO>> getFingerCopyByPage(@RequestBody PaginationBO<FingerCopyQueryBO> queryBO, HttpServletRequest request) {
        try {
            return fingerService.getFingerCopyByPage(queryBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }

    /**
     * @Description: 指纹审核导出
     * @Author: tsz
     */
    @ApiOperation("指纹审核导出")
    @RequestMapping(value = "/fingerAuditExport")
    @ResponseBody
    public void fingerAuditExport(HttpServletResponse response, @RequestBody FingerCopyQueryBO fingerCopyQueryBO, HttpServletRequest request) {
        fingerService.fingerAuditExport(response,fingerCopyQueryBO,request);
    }

    @RequestMapping(value = "/auditFinger", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("指纹信息审核")
    public BaseResult auditFinger(@Validated @RequestBody FingerAuditBO auditBO, HttpServletRequest request) {
        try {
            return fingerService.auditFinger(auditBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }

    @RequestMapping(value = "/BatchAuditFinger", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("指纹信息批量审核")
    public BaseResult batchAuditFinger(@Validated @RequestBody FingerAuditBO auditBO, HttpServletRequest request) {
        try {
            return fingerService.batchAuditFinger(auditBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }

    @RequestMapping(value = "/downloadFigner", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("指纹下载")
    public BaseResult<List<DownloadFingerResDTO>> downloadFigner(@Validated @RequestBody OpFingerReqBO reqBO, HttpServletRequest request) {
        try {
            return fingerService.downloadFigner(reqBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }
    @RequestMapping(value = "/batchDownloadFigner", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("批量指纹下载")
    public BaseResult<List<DownloadFingerResDTO>> batchDownloadFigner(@Validated @RequestBody OpFingerReqBO reqBO, HttpServletRequest request) {
        try {
            return fingerService.batchDownloadFigner(reqBO, request);
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }

    @RequestMapping(value = "/fingerConvert", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("指纹用户ip数据同步")
    public BaseResult<List<OpFingerResDTO>> fingerConvert() {
        try {
            return fingerService.fingerConvert();
        } catch (Exception e) {
            log.error(ErrMessageConst.SYSTEM_ERROR, e);
            return GetResult.getResultErr();
        }
    }



}
